﻿#include"XQPushClient.h"
#include"XQHttpClient.h"
#include"XQHttpHeadRequest.h"
#include"XQUserInfo.h"
#include"XQAlgorithm.h"
using namespace XQPush;
XQPushClient::XQPushClient(QObject* parent)
	:XQHttpRequestObject(parent)
{
	init();
}

XQPushClient::~XQPushClient()
{
}

XQPush::Error XQPushClient::error()
{
	return m_error;
}

XQHttpRequestAccount* XQPushClient::account() const
{
	return m_account;
}

//void XQPushClient::setName(const QString& name)
//{
//	XQHttpRequestObject::setName(name);
//	
//}

void XQPushClient::bindName(QString* name)
{
	XQHttpRequestObject::bindName(name);
	if (m_account)
		m_account->bindName(name);
}

void XQPushClient::setHttp(XQHttpClient* http)
{
	XQHttpRequestObject::setHttp(http);
	if (m_account)
		m_account->setHttp(http);
}


void XQPushClient::init()
{
	account_init();
	m_http = new XQHttpClient(NetworkType::Tcp,this);
	setHttp(m_http);
	m_userInfo = new XQUserInfo(this);
}

void XQPushClient::account_init()
{
	m_account = new XQHttpRequestAccount(this);
	m_account->bindLogName(m_pLogName);
	m_account->bindDebugModels(m_pDebug);
	m_account->bindName(m_pName);
}

void XQPushClient::send(const QByteArray& data)
{
	m_http->post(data.toBase64());
}

void XQPushClient::resultProcessing(XQPush::Result result)
{
	auto data = QByteArray::fromBase64(m_http->toByteArray());
	auto json=QJsonDocument::fromJson(data).object();
	
}

void XQPushClient::replyRead(const XQHttpHeadReply& reply)
{
	//XQHttpRequestAccount::replyRead(reply);
}
